﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebAPI.DAL;
using WebAPI.Models;

namespace WebAPI.Controllers
{
    public class GoodsTypeController : BaseApiController
    {        
        /// <summary>
        /// 获取一级分类
        /// </summary>
        /// <returns></returns>
        public IEnumerable<GoodsType> GetOnelevelGoodsTypeList()
        {
            var list = from g in db.GoodsType where g.fatherTypeId==0 select g;
            return list;
        }

        /// <summary>
        /// 根据父级分类id获取数据
        /// </summary>
        /// <returns></returns>
        public IEnumerable<GoodsType> GetListByFatherTypeId(int id)
        {
            var list = from g in db.GoodsType where g.fatherTypeId == id select g;
            return list;
        }

        public IHttpActionResult Get(int id)
        {
            var type = db.GoodsType.FirstOrDefault((p) => p.Id == id);
            return Ok(type);
        }
    }
}
